﻿using System;
using Sinacor.Infra.UI.Common;
using Sinacor.Infra.UI.Security.Services;
using Sinacor.UI.Bovespa.Parametro.Communication.Bovespa.Operador.Operador;

namespace Sinacor.UI.Bovespa.Parametro.Communication
{
    public class Operador : BaseCommunication
    {
        #region Construtor
        public Operador(SessionInformation session)
            : base(session)
        {

        }
        #endregion

        #region Metodos

       /// <summary>
        /// Retornar a Lista de Operador
       /// </summary>
       /// <param name="request"></param>
       /// <returns></returns>
        public ModelCollection<Model.Operador> ConsultarOperadores(Model.Parameter.FiltroOperador request)
        {
            IOperador servico = null;
            ModelCollection<Model.Operador> retorno = null;
            try
            {
                using (ServiceInstance<IOperador> service = new ServiceInstance<IOperador>())
                {
                    servico = service.TryGetInstance(this.Session);

                    retorno = new Translator.DataContractToModel.Operador().ToOperador
                                (
                                    servico.ConsultarOperadores(new Translator.ModelToDataContract.Operador().ToFiltroOperadorRequest(request))
                                );
                }
            }
            catch (Exception ex)
            {
                this.HandleFault(ex);
            }

            return retorno;
        }
        
        #endregion

    }
}
